package ch08
{
	import flash.display.Sprite;
	import flash.events.Event;

	import utils.Ball;

	/**
	 * 移动的目标.
	 * 鼠标跟随缓动.
	 * @author sjp
	 *
	 */
	public class EaseToMouse extends Sprite
	{
		private var ball:Ball;
		//速度比例系数
		private var easing:Number=0.2;

		public function EaseToMouse()
		{
			init();
		}

		private function init():void
		{
			ball=new Ball();
			addChild(ball);
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		private function onEnterFrame(event:Event):void
		{
			var vx:Number=(mouseX - ball.x) * easing;
			var vy:Number=(mouseY - ball.y) * easing;
			ball.x+=vx;
			ball.y+=vy;
		}
	}
}